fix(create-database): server-driven dialog (#927)#953
Conversation
…riven # Conflicts: # CHANGELOG.md # Plugins/PostgreSQLDriverPlugin/PostgreSQLPluginDriver.swift
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d27c3f6388
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if templateDefaults.collate != collation { | ||
| sql += " TEMPLATE template0" |
There was a problem hiding this comment.
Append template0 when LC_CTYPE differs from template1
In the libc path you set both LC_COLLATE and LC_CTYPE to the selected collation, but you only add TEMPLATE template0 when template1.datcollate differs. On clusters where template1.datctype is different (valid when initdb configured them separately), this branch omits template0 even though LC_CTYPE no longer matches template1, and PostgreSQL rejects CREATE DATABASE with a template locale mismatch. The template decision should account for both datcollate and datctype.
Useful? React with 👍 / 👎.
|
|
||
| private func resetGroupedFields(after sourceId: String, in spec: CreateDatabaseFormSpec) { | ||
| for field in spec.fields where field.groupedBy == sourceId { | ||
| values[field.id] = defaultValue(from: field.kind) ?? "" |
There was a problem hiding this comment.
Reset grouped fields to a value valid for the new group
When a source field changes, dependent grouped fields are reset to their static defaultValue, which can belong to the previous group (for example, MySQL collation default tied to the initial/server charset). That leaves the dependent picker with a stale selection outside the newly filtered options, and submission sends an invalid collation/charset pair that the driver rejects. The reset logic should pick a value from the current group (or clear it) instead of reusing the global default.
Useful? React with 👍 / 👎.
9ff44ff to
b322169
Compare
Summary
Rewrite the Create Database flow to be server-driven instead of using a hardcoded macOS-flavored locale list.
Closes #927. The reported failure (
new collation (en_US.UTF-8) is incompatible with the collation of the template database (en_US.utf8)) was the visible symptom of an architectural smell across four engines:en_US.UTF-8always sent asLC_COLLATE, noLC_CTYPE, never usedTEMPLATE template0(the workaround Postgres itself recommends in the error HINT).LC_COLLATEwhich is invalid Redshift grammar. Real Redshift usesCOLLATE { CASE_SENSITIVE | CASE_INSENSITIVE }. Any user hitting Create Database on a real cluster was failing.Architecture
The dialog is now driver-driven. Plugin kit gains
PluginCreateDatabaseFormSpecdescribing fields (with options, defaults, visibility, grouping) discovered from the server. The view renders generically. The driver builds the SQL from a typed request struct.createDatabaseFormSpec()+createDatabase(_ request:)replace the old(name, charset, collation)shape.PluginKitABI bumped 7 → 8 across all 21 plugin Info.plists.CreateDatabaseOptions.swiftdeleted (hardcoded list).PostgreSQL specifics
template1.datcollate/datctypediscovered frompg_collationandpg_database.LC_CTYPEmirrorsLC_COLLATE(one picker, two clauses).TEMPLATE template0appended automatically when the chosen libc collation differs fromtemplate1.datcollate. Hard error iftemplate1lookup fails (no silent fallback to the original bug).pg_collation).LOCALE, PG 15 usesICU_LOCALEwithLC_COLLATE 'C' LC_CTYPE 'C'."16.2","160002"(libpq numeric), and"PostgreSQL 16.2 on x86_64...".pg_collationfilter includes'b'(built-in) soCandPOSIXshow up on PG 16+.MySQL/MariaDB
information_schema.character_sets/collations.SHOW VARIABLES.groupedBy: "charset").fetchSessionVariabletyped to aSessionVariableenum (no string-interpolation injection vector).Redshift
COLLATEpicker (CASE_SENSITIVE/CASE_INSENSITIVE).Files
47 files changed, +943/−298. New:
PluginCreateDatabaseFormSpec.swift,CreateDatabaseFormSpec.swift,MySQLPluginDriver+CreateDatabase.swift. Deleted:CreateDatabaseOptions.swift.Supersedes #950 (a 2-line tactical patch that hardcoded
template0for one path).Test plan
en_US.UTF-8): default selection works, create succeeds.postgres:16on Linux (template1 =en_US.utf8): reproduces can not create new postgresql database #927 on main; with this PR, server default works and a different collation auto-usesTEMPLATE template0.ICU_LOCALE.LOCALE.COLLATEpicker shown; emitsCOLLATE CASE_SENSITIVE/CASE_INSENSITIVE.information_schema; default = server default; charset change clears stale collation.xcodebuild -project TablePro.xcodeproj -scheme TablePro -configuration Debug build -skipPackagePluginValidationpasses.swiftlint lint --strictpasses.